package colicious.web;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import colicious.service.OrderManager;
import colicious.service.ProductManager;


public class InventoryController implements Controller {
	protected final Log logger = LogFactory.getLog(getClass());
	private ProductManager productManager;
	private OrderManager orderManager;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String now = (new java.util.Date()).toString();
		logger.info("returning hello view with " + now);

		Map<String, Object> myModel = new HashMap<String, Object>();
		myModel.put("now", now);
		myModel.put("products", this.productManager.getProducts());
		myModel.put("orders", this.orderManager.getOrders());
		
		// ESP added 2 lines
		String close = new String("23:59:59 EST");
		myModel.put("close", close);
		
		return new ModelAndView("main", "model", myModel);
	}

	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}
	
	public void setOrderManager(OrderManager orderManager) {
		this.orderManager = orderManager;
	}
}